public class demo1 {
      public class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }
    public ListNode reorderList(ListNode head) {
          if(head==null||head.next==null)return head;
          ListNode newhead=null;
          ListNode cur=head;
          int n=0;
      while(cur!=null) {
           ListNode ncur = cur.next;//暂存下一个节点
          cur.next = newhead;// 反转当前节点的指针
          newhead = cur;// 移动前一个节点到当前节点
          cur = ncur;// 移动到下一个节点
      }
      return  newhead;
    }
}
